package com.atguigu.day10.test14;

public class Test14_2 {
    public static void main(String[] args) {
        Graphic[] all = new Graphic[3];
        all[0] = new Circle(2);
        all[1] = new Rectangle(2, 3);
        all[2] = new Triangle(3, 4, 5);

        Test14_2 a = new Test14_2();
        System.out.println("排序前：");
        a.foreach(all);

        a.sort(all);

        System.out.println("排序后：");
        a.foreach(all);
    }
    void foreach(Graphic[] g){
        for (int i = 0; i < g.length; i++) {
            System.out.println(g[i].getInfo());
        }
    }
    Graphic[] sort(Graphic[] g){
//        Graphic[] c = new Graphic[g.length];
        for (int i = 1; i < g.length; i++) {
            for (int j = 0; j < g.length-i; j++) {
                if (g[j].getArea()>g[j+1].getArea()){
                    Graphic temp = new Graphic();
                    temp = g[j];
                    g[j] = g[j+1];
                    g[j+1] = temp;
                }
            }
        }
        return g;
    }
}
